package cn.com.server.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import cn.com.server.dao.ProductListDao;
import cn.com.server.entity.ProductDetail;
import cn.com.server.entity.ProductMain;
import cn.com.server.service.ProductListService;
import cn.com.server.extend.model.ProductListModel;
import cn.com.server.extend.view.ProductListView;

@Service
public class ProductListServiceImpl implements ProductListService{
	
	@Autowired
	private ProductListDao dao;

	@Override
	public Page<ProductListView> selectProductListModel(ProductListModel model) {
		PageHelper.startPage(model.getPage(), model.getLimit());
		Page<ProductListView> pageData = dao.selectProductListModel(model);
		return pageData;
	}
	
	@Override
	@Transactional
	public boolean createProduct(ProductMain productMain, List<ProductDetail> productDeatilList) {
		dao.createProductMain(productMain);
		for(ProductDetail productDetail:productDeatilList){
			productDetail.setProductMainId(productMain.getId());
			dao.createProductDetail(productDetail);
		}
		return false;
	}
}
